<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="auth" uri="http://www.recharge.com/authority" %>
<auth:authority role="0" />
<%--
这边要注意一个easyui 的问题，当panel tabs 这种href 引用页面
页面中不能有html body head 因为他只会把body 里面的内容 append 到页面中
--%>
<div id="dataCondition" class="easyui-panel"
     style="width:100% 1150px;height:150px;padding:10px;background:#fafafa;"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:false">
    <form id="merchant-mainForm" method="post">

        <table>
            <tr>
                <td><label for="merId">商户Id:</label></td>
                <td><input class="easyui-validatebox" type="text" name="merId" id="merId"/></td>
                <td><label for="merName">商户名称:</label></td>
                <td><input class="easyui-validatebox" type="text" name="merName" id="merName"/></td>
            </tr>

            <tr>
                <td colspan="3"></td>
                <td><input type="button" id="submit_merchant-mainForm" value="查询" onclick="submitMarchantMainForm();">
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="dataView" class="easyui-panel" title="查询结果"
     style="width:100% 1150px;background:#fafafa; height: 415px;overflow-y:hidden"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:false">
    <table id="merchant-dg">
    </table>
</div>

<div id="merchant-detailDialog"></div>

<script language="JavaScript" type="text/javascript">

    $().ready(function () {

        //初始化查询结果表格
        $('#merchant-dg').datagrid({
            columns:[[
                {field:'merId',title:'商户id',width:100},
                {field:'merName',title:'商户名称',width:150},
                {field:'merStatus',title:'状态',width:100},
                {field:'balance',title:'余额',width:100},
            ]],
            pagination: true,
            height: 390,
            toolbar: [{
                iconCls: 'icon-add',
                text : "商户加款",
                handler: function(){
                    $('#merchant-detailDialog').dialog({
                        title: '商户加款',
                        width: 400,
                        height: 200,
                        closed: false,
                        cache: false,
                        href : "tradeMerchant/balanceAdd.jsp",
                        modal: true
                    });
                }
            }]
        });

        var pager = $('#merchant-dg').datagrid().datagrid('getPager');
        pager.pagination({
            onBeforeRefresh:function(pageNumber, pageSize){
                getListData(pageNumber,pageSize);
            },
            onSelectPage:function(pageNumber, pageSize){
                getListData(pageNumber,pageSize);
            }
        });
    });

    function getListData(pageNumber, pageSize){
        var param = $("#merchant-mainForm").serializeArray();
        param.push({name:"curr",value:pageNumber});
        param.push({name:"pageSize",value:pageSize});
        
        $.post("tradeMerchant/queryMerList", param,function(responseInfo){
            $('#merchant-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });
    }

    function submitMarchantMainForm() {
        var param = $("#merchant-mainForm").serializeArray();
        param.push({name:"curr",value:1});
        param.push({name:"pageSize",value:10});
        $.post("tradeMerchant/queryMerList", param,function(responseInfo){
            $('#merchant-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });
    }
</script>